import pymysql
import threading
db = pymysql.connect(host= 'localhost',user='root',password='0830',database='链家')
cursor = db.cursor()
lock = threading.RLock() # 获取锁
def updateTable(sql):
    '''
    添加数据
    :param sql:
    :return:
    '''
    try:
        lock.acquire()  # 加锁
        cursor.execute(sql)
        db.commit()
        lock.release()  # 解锁
    except Exception as e:
        print(e)
        db.rollback()
def selectTable(sql):
    cursor.execute(sql)
    result = cursor.fetchall()
    return result

def query(sql):
    '''
    查询
    :param sql:
    :return:
    '''
    cursor.execute(sql)
    result = cursor.fetchall()
    return result
